const http = require('http')
const fs = require('fs')

const server = http.createServer()

//请求对象req
server.on('request',(req,res)=>{
    console.log('我的服务被请求了');
    const str = `your request url is ${req.url},请求方法是 ${req.method}`
    
    //解决中文乱码,设置请求头 Contene-Type 的值为 text/html; charset=utf-8
    res.setHeader('Content-Type','text/html; charset=utf-8')

    //响应的方法  res.end(),并结束这次响应处理过程
    res.end(str)
})

//启动服务
server.listen(8080,()=>{
    console.log('server running at http://127.0.0.1:8080');
})